/*
 * @Author: chenr 526963089@qq.com
 * @Date: 2023-11-14 11:51:18
 * @LastEditors: chenr 526963089@qq.com
 * @LastEditTime: 2023-12-05 09:28:16
 * @FilePath: /lottery-draw/vite.config.ts
 * @Description:
 */
import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import { resolve } from 'node:path';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';

const root = process.cwd();
const pathResolve = (pathname: string) => resolve(root, '.', pathname);

export default defineConfig({
  plugins: [
    uni(),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  resolve: {
    alias: [
      // /@/xxxx => src/xxxx
      {
        find: /\/@\//,
        replacement: pathResolve('src') + '/',
      },
      // /#/xxxx => types/xxxx
      {
        find: /\/#\//,
        replacement: pathResolve('types') + '/',
      },
      // @/xxxx => src/xxxx
      {
        find: /@\//,
        replacement: pathResolve('src') + '/',
      },
      // #/xxxx => types/xxxx
      {
        find: /#\//,
        replacement: pathResolve('types') + '/',
      },
    ],
  },
  server: {
    proxy: {
      '/basic-api': {
        // target: 'https://draw.laybg.com',
        target: 'http://houtai.2dc1l.com',
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(new RegExp(`^/basic-api`), ''),
      },
    },
  },
});
